package com.bjsxt.shop.users.test;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.bjsxt.shop.goods.util.MyThreadUtil;

/**
 * 测试所有的代码
 * 
 * @author WangshSxt
 *
 */
public class ThradMain
{
	public static void main(String[] args)
	{
		/*------JDK 1.4自带的-----*/
		/* 创建固定的线程池 */
		ExecutorService executorService = Executors.newFixedThreadPool(5);
		for(int i = 0 ; i < 5 ; i ++)
		{
			MyThreadUtil myThreadUtil = new MyThreadUtil() ; 
			/* 提交一个线程 */
			executorService.submit(myThreadUtil);
		}
		/* 关闭 */
		executorService.shutdown();
		/* 主线程不等待 */
		System.out.println("==================");
		
		/*------主线程等待-----*/
		try
		{
			List threadList = new ArrayList();
			for(int i = 0 ; i < 5 ; i ++)
			{
				MyThreadUtil myThreadUtil = new MyThreadUtil() ; 
				threadList.add(myThreadUtil);
			}
			executorService = Executors.newFixedThreadPool(threadList.size());
			executorService.invokeAll(threadList);
		} catch (Exception e)
		{
			e.printStackTrace();
		}finally
		{
			executorService.shutdown();
		}
		System.out.println("========Over==========");
	}
}
